''' 房间录制 '''
import functools, asyncio, re, sys, os
# sys.path.append('..')
from pymud import Alias, Trigger, SimpleCommand, SimpleTrigger, SimpleAlias, Timer
from prompt_toolkit.mouse_events import MouseEvent, MouseEventType
from settings import Settings
# from mysqlPack import mysql
# from t1 import mmm
# print(mmm.bbbb())

class Configuration:
    room = {
        "name":["rname","area"],
        "info":['line1','line2','line3','line4'],
        "exits":['d1','d2','d3','d4','d5','d6','d6','d8']
    }

    def __init__(self, session) -> None:
        self.session = session
        self._triggers = {}
        self._initTriggers()
        # row = mysql.CURD.select()
        # self.session.info(row[0][2])
    
    def _initTriggers(self):
        self._triggers["get_room1"] = Trigger(self.session,
            r"^「(.+)」\s\-\s\(你目前在(.+)\)",
            group="tri_get_room", id="get_room1",
            onSuccess = self._onTriggersGetRoomName
        )
        self._triggers["get_room2"] = Trigger(self.session,
            patterns=(
                r"^\s*(?!｜)(\S+)",
                r"^\s*(?!｜)(\S+)",
                r"^\s*(?!｜)(\S+)",
                r"^\s*(?!｜)(\S+)",
                # r"^\s+〖\s*出口\s*〗",
            ),
            group="tri_get_room", id="get_room2",
            onSuccess = self._onTriggersGetRoomInfo
        )
        # self._triggers["get_room3"] = SimpleTrigger(self.session,
        self._triggers["get_room3"] = Trigger(self.session,
            # r"^\s+〖\s出口\s〗:\s((\w+)、)+(\w+)\s和\s(\w+)。",
            r"^\s+〖\s出口\s〗:\s(.*)。",
            # 'say haha',
            group="tri_get_room", id="get_room3", keepEval = True,
            onSuccess = self._onTriggersGetRoomExits
        )
        # self._triggers["get_room4"] = Trigger(self.session,
        #     r"^\s+唯一的〖\s出口\s〗:\s(\w+)。",
        #     # 'say haha',
        #     group="tri_get_room", id="get_room4",
        #     onSuccess = self._onTriggersGetRoomExits2
        # )
        self.session.addTriggers(self._triggers)

    # 抓取房间 名称
    def _onTriggersGetRoomName(self, name, line, wildcards):
        # self.session.info(wildcards)
        self.session.setVariables(self.room["name"], wildcards)
        var = self.session.getVariables(self.room["name"])
        # self.session.info(var)
    # 抓取房间 描述
    def _onTriggersGetRoomInfo(self, name, line, wildcards):
        # self.session.info(wildcards)
        self.session.setVariables(self.room["info"], wildcards)
        var = self.session.getVariables(self.room["info"])
        # self.session.info(var)
        # mysql.CURD.select()

    # 抓取房间 出口
    def _onTriggersGetRoomExits(self, name, line, wildcards):
        self.session.info(line)
        self.session.info(wildcards)

        matchs = re.match(r"\w", line)

        # self.session.info(matchs)
        # self.session.setVariables(self.room["exits"], wildcards)
        # var = self.session.getVariables(self.room["exits"])
        # self.session.info(var)
    def _onTriggersGetRoomExits2(self, name, line, wildcards):
        self.session.info(wildcards)
        # self.session.setVariables(self.room["exits"], wildcards)
        # var = self.session.getVariables(self.room["exits"])
        # self.session.info(var)

        '''.
「巫师会客室」 - (你目前在仙界)
    这里是巫师和玩家交流的地方，如果你有什么问题需要向巫师请
教，可以在这里留言(post)。不过如果问题牵涉到解谜或者已经在帮
助文件里有详细说明，巫师们就不一定会回答。楼上是巫师休息室，
一般玩家到这里后就上不去了
    〖 出口 〗: south、north 和 up。
    〖 出口 〗: east、east、west 和 up。
    落魄公子往北方离开。
你从腐烂的男尸中拿出一些银子。
你从腐烂的男尸中拿出一件布衣。
你从腐烂的男尸中拿出一柄长剑。
  四位流氓(liu mang)
  流氓头的尸体(Corpse)
  二两银子(Silver)
  二柄长剑(sword)
  布衣(cloth)
  包子(baozi)
  牛皮水袋(shui dai)
  钢杖(staff)
  铁甲(armor)
        '''